package sim.helpers.statistics;

import java.util.LinkedList;

public class StatisticsHolder {

    protected LinkedList<ValueHolder> valueList;

    public StatisticsHolder(){
        valueList = new LinkedList<ValueHolder>();
    }

    public void addValue(ValueHolder value){
        valueList.add(value);
    }

    public ValueHolder getValue(int index){
        return valueList.get(index);
    }

    public ValueHolder getValueHolderByIndex(int index){
        ValueHolder ret = null;
        for (ValueHolder vh : valueList) {
            if (vh.getIndex() == index){
                ret = vh;
                break;
            }
        }
        return ret;
    }

    public ValueHolder getValueHolderByValue(double value){
        ValueHolder ret = null;
        for (ValueHolder vh : valueList) {
            if (vh.getValue() == value){
                ret = vh;
                break;
            }
        }
        return ret;
    }

    public double getAvgValue(){
        double ret = 0;
        for (ValueHolder valueHolder : valueList) {
            ret += valueHolder.getValue();
        }
        return ret/valueList.size();
    }

    public LinkedList<ValueHolder> getValueList() {
        return valueList;
    }

    public void setValueList(LinkedList<ValueHolder> valueList) {
        this.valueList = valueList;
    }

}
